package leetcode.剑指offer.后40;

import org.junit.Test;

/**
 * @author :songyaozhang
 * @date :Created 2021/8/6 19:04
 * @description :https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/
 */
public class 剑指_56_II数组中数字出现的次数II {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.singleNumber(new int[]{9,1,7,9,7,9,7}));
    }

    class Solution {
        public int singleNumber(int[] nums) {
            int ans = 0;
            for (int i = 0; i < 32; i++) {
                int ret = 1 << i;
                int count = 0;
                for (int num : nums) {
                    if ((ret & num) != 0) count++;
                }
                if (count % 3 != 0)
                    ans |= ret;
            }
            return ans;
        }
    }
}
